using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !SILVERLIGHT
using System.Threading;
#endif

namespace Gko.Utils
{
#if SILVERLIGHT
	internal static class ReaderWriterLockSlimExtensions
#else
	public static class ReaderWriterLockSlimExtensions
#endif
	{
		public static IDisposable Write(this ReaderWriterLockSlim slim)
		{
			slim.EnterWriteLock();
			return Scope.Create(slim.ExitWriteLock);
		}

		public static IDisposable Read(this ReaderWriterLockSlim slim)
		{
			slim.EnterReadLock();
			return Scope.Create(slim.ExitReadLock);
		}

#if !SILVERLIGHT
		public static IDisposable UpgradeableRead(this ReaderWriterLockSlim slim)
		{
			slim.EnterUpgradeableReadLock();
			return Scope.Create(slim.ExitUpgradeableReadLock);
		}
#endif
	}
}
